package com.qcby.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.qcby.Constants;
import com.qcby.model.Hall;
import com.qcby.model.dto.HallQueryDto;
import com.qcby.model.dto.HallVo;
import com.qcby.model.resp.RespEntity;
import com.qcby.service.HallService;
import com.qcby.util.Page;

@RestController
@RequestMapping("/hall")
public class HallController {

    @Autowired
    private HallService hallService;

    @RequestMapping("/selectAll")
    public RespEntity<List<Hall>> selectAll(){
        List<Hall> halls=hallService.selectObjectAll();
        return RespEntity.successCustomize(Constants.FLAG_200, "查询成功！", halls);
    }
    /**
     * 查询
     */
    @RequestMapping("/list")
    public RespEntity<Page<HallVo>> searchHall(@RequestBody HallQueryDto hallQueryDto) {
        if (hallQueryDto != null) {
            if (hallQueryDto.getPageNo() == null) {
                hallQueryDto.setPageNo(1);
            }
            Page<HallVo> page = hallService.query(hallQueryDto.getHName(), hallQueryDto.getCId(),
                hallQueryDto.getPageNo(), hallQueryDto.getPageSize());
            System.out.println(page);
            //返回所有的影院信息
            return new RespEntity<>(Constants.FLAG_200, "查询成功", page);
        }
       return RespEntity.errorCustomize(Constants.FLAG_400,"参数不能为空",null);
    }
    /**
     * 添加
     */
    @RequestMapping("/addHall")
    public RespEntity<String> addHall(@RequestBody Hall hall) {
         if(hall!=null){
                 //这部分内容 cid应该通过下拉框匹配
                 System.out.println(hall);
                 hallService.insert(hall);
             return RespEntity.successCustomize(Constants.FLAG_200, "添加成功", null);
             }
        return RespEntity.errorCustomize(Constants.FLAG_400,"","添加失败");
    }

    /**
     * 修改
     */
   //获取ID对应的信息
    @RequestMapping("/getById")
    public RespEntity<Hall> getById(Integer hId){
        if(hId!=null){
            System.out.println(hId);
            Hall hall=hallService.selectByPrimaryKey(hId);
            System.out.println(hall);
            return RespEntity.successCustomize(Constants.FLAG_200,"",hall);
        }
        return RespEntity.errorCustomize(Constants.FLAG_400,"",null);
    }
    //修改操作
    @RequestMapping("/updateHall")
    public RespEntity<String> updateHall(@RequestBody Hall editHall){
        System.out.println(editHall);
        //必须要回显行数和列数  才可以修改容量
        if(editHall!=null){
            hallService.updateByPrimaryKeySelective(editHall);
            return RespEntity.successCustomize(Constants.FLAG_200,"","修改成功");
        }
        return RespEntity.errorCustomize(Constants.FLAG_400,"","修改失败");
    }

    @RequestMapping("/delete/{hId}")
    public RespEntity<String> delete(@PathVariable Integer hId) {
        hallService.deleteByPrimaryKey(hId);
        return RespEntity.successNoData("删除影厅成功！");
    }

}
